package com.lagou.mapper;

import com.lagou.domain.Orders;
import com.lagou.domain.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @Author wsl
 * @Date 2021/11/4 21:37
 * @Project_Name mybatis_quickstart
 */
public interface OrderMapper {

    /**
     * 1.一对一查询：查询所有订单，与此同时查询出每个订单所属的用户信息 (注解方式)
     * @return
     */
    @Select("select * from orders")
    @Results({//代替resultMap标签 id标签 result标签
            @Result(property = "id", column = "id", id = true),
            @Result(property = "ordertime", column = "ordertime"),
            @Result(property = "total", column = "total"),
            @Result(property = "uid", column = "uid"),
             @Result(property = "user", javaType = User.class, column = "uid", one = @One(select = "com.lagou.mapper.UserMapper.findById",fetchType = FetchType.EAGER)),
    })
    public List<Orders> findAllWithUser();

    /**
     * 2.用于一对多查询：根据用户传递过来的用户id,查询出该用户的订单信息
     * @param uid
     * @return
     */
    @Select("select * from orders where uid = #{uid}")
    public List<Orders> findOrderByUid(Integer uid);
}
